CC=g++
CFLAGS=-g 

all: libqythread.a liburlconn.a server client

libqythread.a: Thread.o ThreadManager.o Mutex.o
	ar -r libqythread.a Thread.o ThreadManager.o Mutex.o

Thread.o: Thread.h Thread.cpp
	$(CC) $(CFLAGS) -c -pthread -o Thread.o Thread.cpp  

ThreadManager.o: ThreadManager.h ThreadManager.cpp Thread.h
	$(CC) $(CFLAGS) -c -pthread -o ThreadManager.o ThreadManager.cpp 

Mutex.o: Mutex.h Mutex.cpp
	$(CC) $(CFLAGS) -c -pthread -o Mutex.o Mutex.cpp


liburlconn.a: URLConnection.o URLRequest.o URLResponse.o 
	ar -r liburlconn.a URLConnection.o URLRequest.o URLResponse.o

URLRequest.o: URLRequest.h URLRequest.cpp
	$(CC) -c URLRequest.cpp

URLResponse.o: URLResponse.h URLResponse.cpp 
	$(CC) -c URLResponse.cpp

URLConnection.o: URLConnection.h URLConnection.cpp URLResponse.h URLRequest.h
	$(CC) -c URLConnection.cpp

TCPChannel.o:	TCPChannel.h TCPChannel.cpp util.h
	$(CC) -c TCPChannel.cpp

TCPServer.o:	TCPServer.h TCPServer.cpp util.h
	$(CC) $(CFLAGS) -c TCPServer.cpp

TCPClient.o:	TCPClient.h TCPClient.cpp util.h
	$(CC) $(CFLAGS) -c TCPClient.cpp

SessionHandler.o:	SessionHandler.h SessionHandler.cpp util.h Thread.h
	$(CC) $(CFLAGS) -c SessionHandler.cpp

util.o:	util.h util.cpp
	$(CC) $(CFLAGS) -c util.cpp

server:	server.cpp TCPServer.o TCPChannel.o util.o SessionHandler.o
	$(CC) $(CFLAGS) -o server server.cpp TCPServer.o TCPChannel.o util.o SessionHandler.o libqythread.a -pthread

client: client.cpp TCPClient.o TCPChannel.o util.o
	$(CC) $(CFLAGS) -o client client.cpp TCPClient.o TCPChannel.o util.o

clean:
	rm *.o *.a server client
